package com.ms.p2p.service.impl;

import com.ms.common.exception.NoticeException;
import com.ms.p2p.dao.BankCardImgDao;
import com.ms.p2p.dao.BankUnBindDao;
import com.ms.p2p.entity.account.BankCardImg;
import com.ms.p2p.entity.account.BankCardImgLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
 * Created by chensk on 2018/3/22.
 */
@Service
public class BankCardLogService {
    @Autowired
    BankUnBindDao dao;

    @Autowired
    BankCardImgDao bankCardImgDao;

    public BankCardImgLog findByUserIdAndBankId(Integer user_id, Integer bank_id, Integer status) {

        return dao.findByUserIdAndBankId(user_id,bank_id,status);

    }
    @Transactional
    public void insert(BankCardImgLog log, List<BankCardImg> list) {
        dao.insert(log);//insert return key 做不到？为啥
        BankCardImgLog logs = null;
        try {
            logs=  dao.findByUserIdAndBankId(log.getUser_id(), log.getBank_id(), 0);
        }catch (Exception e) {
            throw new NoticeException("别重复提交");
        }
        for (BankCardImg img:list){
            img.setLog_id(logs.getId());
            bankCardImgDao.insert(img);
        }


    }

    public java.util.List<Map<String,Object>> unbindList() {
        return dao.unbindList();
    }

    public BankCardImgLog findById(Integer id) {
        return dao.findById(id);
    }

    public void update(BankCardImgLog bankCardImgLog) {
        dao.update(bankCardImgLog);
    }
}
